#pragma once

#include "SoapCore.h"
#include "PublicUtil.h"

struct CSdpPayload
{
	int m_nLineIdx;	/* the index of the m= line */
	int m_nPaylodType;		/*payload type */
	int m_nLocalPort;
	int m_nRemotePort;
	int m_nBAsBandwidth;	/* application specific bandwidth */
    string m_strProto;
	string m_strNetType;
	string m_strAddrType;
	string m_strAddr;
	string m_strAddrMulticastTTL;
	string m_strAddrMulticastInt;
	string m_str_a_rtpmap;
	string m_str_a_fmtp;
	string m_strRelayHost;
	int    m_nRelayPort;
	string m_strRelaySessionId;
	int    m_n_a_ptime;

	CSdpPayload()
	{
		m_nLineIdx = 0;
	}
} ;


class CSdpProcessor
{
public:
	CSdpProcessor(CSoapCore::CSoapCall* pSoapCall);
	~CSdpProcessor(void);

public:

	enum SdpContextState
	{
		SDP_CONTEXT_STATE_INIT,
		SDP_CONTEXT_STATE_NEGOCIATION_OPENED,
		SDP_CONTEXT_STATE_NEGOCIATION_CLOSED
	} ;

public:
	string m_strLocalIp;
	string m_strUserName;

	sdp_message_t *m_pSdpOffer;		/* the local sdp to be used for outgoing request */
	string m_strOffer;
	sdp_message_t *m_pSdpAnswer;		/* the local sdp generated from an inc request */
	string m_strAnswer;
	string m_strRelay;
	string m_strRelaySessionId;
	int m_nNegocStatus;	/* in sip code */
	int m_nIncb;
	SdpContextState m_stateNegoc;

public:
	string GetOfferSdp();
	//sdp_handler_read_codec_func_t accept_audio_codecs;   /*from remote sdp */
	//sdp_handler_read_codec_func_t accept_video_codecs;   /*from remote sdp */
	//sdp_handler_write_codec_func_t set_audio_codecs;	/*to local sdp */
	//sdp_handler_write_codec_func_t set_video_codecs;	/*to local sdp */
	//sdp_handler_read_codec_func_t get_audio_codecs;	/*from incoming answer  */
	//sdp_handler_read_codec_func_t get_video_codecs;	/*from incoming answer  */

private:
    CSoapCore* m_pSoapCore;
	CSoapCore::CSoapCall* m_pSoapCall;
private:
	void SetAudioOffer();
	void AddPayloadToAdpMsg (CSdpPayload& payload, string strMedia);
	sdp_message_t* CreateSdpGenerateTemplate();
	void AddRelayInfo(sdp_message_t *sdp, int mline, const char *relay, const char *relay_session_id);
	char* int_2char(int a);
};
